﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using System.Data;

namespace DataAccess
{
    public partial class MSAccessDataAccess : IDataAccess
    {
        #region IDataAccess Members

        public TableInformation QueryValidation(ConnectionInformation connectionInformation, string QueryString)
        {
            TableInformation tableInformation = new TableInformation();

            tableInformation.DataTable = ExecuteQuery(connectionInformation, QueryString);

            tableInformation.ColumnList = new List<Column>();

            int count = tableInformation.DataTable.Columns.Count;

            for (int i = 0; i < count; i++)
            {
                tableInformation.ColumnList.Add(new Column() { Name = tableInformation.DataTable.Columns[i].ColumnName, Type1 = tableInformation.DataTable.Columns[i].DataType.Name, IsImported = true });
            }
            
            return tableInformation;
        }
        #endregion

        //private string[] ExtractTableName(string QueryString)
        //{
        //    QueryString = QueryString.ToLower();
        //    int fromIndex = QueryString.IndexOf("from");
        //    int whereIndex = QueryString.IndexOf("where");
        //    fromIndex += 4;

        //    if (whereIndex != -1)
        //        QueryString = QueryString.Substring(fromIndex, whereIndex - fromIndex);
        //    else
        //        QueryString = QueryString.Substring(fromIndex);

        //    QueryString = QueryString.Replace(" ", "");

        //    string[] str = QueryString.Split(","[0]);

        //    int l = str.Length;

        //    for (int i = 0; i < l; i++)
        //    {
        //        if (str[i].Contains('.'))
        //        {
        //            str[i] = str[i].Split("."[0])[1];
        //        }
        //    }
        //    return str;
        //}

        #region IDataAccess Members

        List<string> IDataAccess.CheckConnection(ConnectionInformation connectionInformation)
        {
            throw new NotImplementedException();
        }

        public List<string> GetViewList(ConnectionInformation connectionInformation)
        {
            throw new NotImplementedException();
        }

        public TableInformation GetViewInformation(ConnectionInformation connectionInformation, string viewName)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}